key = "870794bc135c41349bd4214854fc9b1c".encode()
text = "Liju2g3oNGMqg23t7c5U7w==".encode()

from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
import binascii

# 生成RSA密钥对
key = RSA.generate(2048)
private_key = key.export_key()
public_key = key.publickey().export_key()


# 加密函数
def encrypt_rsa(message, public_key):
    rsa_public_key = RSA.import_key(public_key)
    rsa_public_key = PKCS1_OAEP.new(rsa_public_key)
    return rsa_public_key.encrypt(message)


# 解密函数
def decrypt_rsa(ciphertext, private_key):
    rsa_private_key = RSA.import_key(private_key)
    rsa_private_key = PKCS1_OAEP.new(rsa_private_key)
    return rsa_private_key.decrypt(ciphertext)


# 加密消息
message = b"Hello, RSA!"
encrypted = encrypt_rsa(message, public_key)
print(f"加密后: {binascii.hexlify(encrypted)}")

# 解密消息
decrypted = decrypt_rsa(encrypted, private_key)
print(f"解密后: {decrypted.decode()}")
